package com.tarena.micro.service.order.controller;

import com.tarena.micro.service.common.result.JsonResult;
import com.tarena.micro.service.order.service.OrderService;
import com.tarena.micro.service.pojo.param.OrderAddParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class OrderController {
    @Autowired
    private OrderService orderService;
    @PostMapping("/order/add")
    public JsonResult addOrder(OrderAddParam param){
        //业务调用 让业务层帮助我完成新增订单功能 反馈成功失败
        orderService.addOrder(param);
        return JsonResult.ok();
    }
    @GetMapping("/order/get")
    public JsonResult<String> getOrder(Integer id){
        //统计一下 查询调用的时长 理论上来说 查询数据库时间>查询redis时间
        Long start=System.currentTimeMillis();
        //根据订单id 查询订单详情
        String orderDetail=orderService.detail(id);
        Long end=System.currentTimeMillis();
        System.out.println("总计消耗时间:"+(end-start)+"MS");
        return JsonResult.ok(orderDetail);
    }
}
